// hyb_yl/record_3/component/record.js
var app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    currentPage:{
      type:Number,
    },
    bg_id:{
      type:String,
    },
    time:{
      type:String,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    bloodClick: function (e) {
      console.log('picker发送选择改变，携带值为', e.detail.value)
      var that = this
      var secArr1 = that.data.secArr1
      var idx = e.currentTarget.dataset.idx
      var indexs = e.currentTarget.dataset.indexs
      // console.log(secArr[indexs])
      secArr1[idx].picker.displayorder = e.detail.value
      secArr1[idx].description = secArr1[idx].picker.items[e.detail.value]
      this.setData({
        secArr1: secArr1
      })
    },
    setListData: function () {
      let _this = this;
      this.setData({
        secArr1: app.globalData.secArr1
      });
      app.globalData.secArr1 = [];
    },
    subClick:function(e){
      console.log(e)
      var myEventDetail = {
        value: e.detail.value
      } // detail对象，提供给事件监听函数
      this.triggerEvent('sub', myEventDetail)
    },
    lastClick:function(e){
      this.triggerEvent('last')
    },
    chooseCheck: function (e) {
      var that = this
      var index = e.currentTarget.dataset.index
      var indexs = e.currentTarget.dataset.indexs
      var secArr1 = that.data.secArr1
      for (var i = 0; i < secArr1.length; i++) {
        if (secArr1[i].displaytype == 1) {
          secArr1[i].items[index].checked = !secArr1[i].items[index].checked
          console.log(secArr1[i])
          if (secArr1[i].items[index].checked) {
            secArr1[i].description += secArr1[i].items[index].title + ";"
          } else {
            secArr1[i].description = secArr1[i].description.replace(secArr[indexs].secArr1[i].items[index].title + ";", "")
          }
        }
      }
      console.log(secArr1)
      that.setData({
        secArr1: secArr1
      })
    },
    //上传图片
    choosePhoto: function (e) {
      var that = this
      var secArr1 = that.data.secArr1
      // console.log(secArr)
      var index = e.currentTarget.dataset.index
      var indexs = e.currentTarget.dataset.indexs
      var idx = e.currentTarget.dataset.idx
      wx.chooseImage({
        count: 9, // 默认9
        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
        success: function (res) {
          // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
          secArr1[idx].items = secArr1[idx].items.concat(res.tempFilePaths)
          secArr1[idx].description = secArr1[idx].items
          if (secArr1[idx].items.length >= 9) {
            secArr1[idx].items.length = 9
          }
          console.log(secArr1)
          that.setData({
            secArr1: secArr1
          })
        }
      })
    },
    //单选
    radioChange: function (e) {
      var that = this
      console.log(e)
      var secArr1 = that.data.secArr1
      var idx = e.currentTarget.dataset.idx
      var indexs = e.currentTarget.dataset.indexs
      secArr1[idx].description = e.detail.value
      // console.log(secArr)
      this.setData({
        secArr1: secArr1
      })
    },
    //单行文本
    lineClick: function (e) {
      console.log(e)
      var that = this
      var secArr1 = that.data.secArr1
      var indexs = e.currentTarget.dataset.indexs
      var idx = e.currentTarget.dataset.idx
      secArr1[idx].description = e.detail.value
      var now = Number(e.detail.value)
      var high = Number(e.currentTarget.dataset.highstandard)
      var low = Number(e.currentTarget.dataset.lowstandard)
      secArr1[idx].time = that.data.time
      if (now < high && now > low){
        secArr1[idx].abnormal = 1
      }else{
        secArr1[idx].abnormal = 0
      }
      that.setData({
        secArr1: secArr1
      })
    },
    //多行
    duohangClick: function (e) {
      console.log(e)
      var that = this
      var secArr1 = that.data.secArr1
      var indexs = e.currentTarget.dataset.indexs
      var idx = e.currentTarget.dataset.idx
      secArr1[idx].description = e.detail.value
      that.setData({
        secArr1: secArr1
      })
    },
  },

  ready: function () {
    this.setListData();
  }
})
